import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Home from '@/components/Home'
import Login from '@/components/Login'





// import UserList from '@/views/user/UserList'
// import AddUser from '@/views/user/AddUser'








Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home,
      beforeEnter(to,from,next){
        //是否登录，没有登录跳转到登录
        let username = sessionStorage.getItem('username')
        if(username){
          next() // 放行
        }
        else{
          alert('没有登录，不能访问')
          next('/login')
        }
      },
      children:[
        
        {
          path:'/userlist',
          component: ()=> 
              import('@/views/user/UserList'),
        },
        
        
      ]
    },{
      path:'/login',
      component: Login
    },
    
    
  ]
})
